package code;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Eventqueue {
	public PriorityQueue<Event> m_buffer_;
	public Eventqueue() {
		m_buffer_ = new PriorityQueue<Event>(11, new Comparator<Event>(){
			public int compare(Event e1, Event e2){
				if (e1.timer_>e2.timer_)
					return 1;
				else
					return -1;
			}
		});
				
	}
	void putinqueue_ (Event e){
		m_buffer_.offer(e);
	}
	
	void out_of_queue_(){
		Event e=m_buffer_.poll();
		if (e== null)
			System.out.println("The event queue is empty");
		else{
			Global.TIME=e.timer_;
			e.execute_();
		}
			
	}
	
	void  initialize_()
	{
		while (Global.TIME<=Global.ENDTIME)
			this.out_of_queue_();
	}

}
